# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=cargo-pgrx
pkgver=0.9.8
pkgrel=1
pkgdesc='Build PostgreSQL extensions with Rust'
arch=('loong64' 'x86_64')
url='https://github.com/tcdi/pgrx'
license=('MIT')
depends=('gcc-libs' 'openssl' 'clang' 'llvm' 'bzip2')
makedepends=('git' 'rust')
optdepends=('postgresql: to compile with system postgresql')
replaces=('cargo-pgx')
options=('!lto')
_commit='fc1112eef9fb912978d157c556edfcd69a9daa3a'
source=("$pkgname::git+$url.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # download dependencies
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$pkgname"

  cargo build --release --frozen --package "$pkgname"
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" "target/release/$pkgname"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
